home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 528 / dcoffset / dcoffset.doc
Text File  |  1989-04-05  |  6KB  |  171 lines

  1. DC Squish is Copyright (c) 1989-91 by Double Click Software.
  2.  
  3. This document describes and gives sample assembly code for the DC Squish
  4. Offset Protocol which allows programs to save information directly to a
  5. SQUISHed program, without damaging the SQUISHed portion of the program.
  6.  
  7. What the protocol defines is a region near the beginning of the program
  8. which is not Squished, but merely copied intact.  DC Squish v1.4 and above
  9. will automatically detect this protocol and give the user the opportunity
  10. to Squish the program using the protocol, when performing a Squish.
  11.  
  12. Programs which are Squished will be required to detect that the program is
  13. Squished, when saving information back to itself, and if it is detected,
  14. seek to the unsquished region, then save the necessary information to the
  15. program.
  16.  
  17. Two sample save routines are included for clarity.  They can be used to
  18. detect the DC Squish Offset Protocol.
  19.  
  20. DC Squish v1.4
  21. ==============
  22.  
  23. Now supports a "protected offset" which can be used to store information
  24. that will not be squished or unsquished - copied only.
  25.  
  26.  
  27. Squish Offset Programmer's Reference
  28. ------------------------------------
  29.  
  30. A check of the file to be Squished is made:
  31.  
  32. TEXT Segment
  33.  1) First word   = 4EF9 (jmp abs.l)
  34.  2) Next long    = Offset
  35.  3) Next word    = Squish cookie.w ($4AFC)
  36.  4) Next 8 bytes = User definable
  37.  
  38. ************************
  39. * Sample program start *
  40. ************************
  41. BEGIN:  jmp     (start).l               ; jmp non-PC relative!
  42. cookie_sq:dc.w  $4afc           ; Squish cookie.w
  43. file_info:dc.b  'TEST1234'      ; ex. filename (user definable)
  44. cfg_info:       ds.l    14              ; configuration info
  45. start:
  46.  
  47. * Note:
  48. * cfg_info = programmer defined size
  49. *          = 128 Kbytes - $1C (program header) - $10 (program start) max.
  50. *            ^^^^^^^^^^ (Squish assigned limit)
  51.  
  52. ***********************
  53. * Sample save routine *
  54. ***********************
  55.         clr.b   chk_sqsh
  56.         clr.w   -(a7)           ; mode
  57.         pea     my_name         ; name
  58.         move.w  #$3d,-(a7)
  59.         trap    #1              ; Fopen
  60.         addq.l  #8,a7
  61.         move.w  d0,f_handle
  62.         bmi.s   .error
  63. .back   pea     scratch         ; buffer
  64.         move.l  #cfg_info-BEGIN+$1c,-(a7)       ; count
  65.         move.w  f_handle,-(a7)  ; handle
  66.         move.w  #$3f,-(a7)
  67.         trap    #1              ; Fread
  68.         lea     12(a7),a7
  69.         cmp.l   d0,d7
  70.         bne.s   .file_err
  71.  
  72.         move.l  2(a6),d7                ; TEXT (Squish loader) length
  73.         moveq   #$1c,d0         ; PRG Header length
  74.         add.l   d0,d7           ; start of Squished file
  75.         add.l   d0,a6           ; program start (loader)
  76.         lea     10(a6),a1               ; Squish check pointer
  77.         lea     BEGIN,a0
  78.         cmp.w   (a6)+,(a0)+     ; jmp?
  79.         bne.s   .chk_sqsh               ; nope
  80.         addq.l  #4,a6           ; skip
  81.         addq.l  #4,a0           ;  offset
  82.         cmp.w   (a6)+,(a0)+     ; cookie.w?
  83.         bne.s   .chk_sqsh               ; nope
  84.         cmp.l   (a6)+,(a0)+     ; me1?
  85.         bne.s   .chk_sqsh               ; nope
  86.         cmp.l   (a6)+,(a0)+     ; me2?
  87.         bne.s   .chk_sqsh               ; nope
  88.  
  89.         pea     cfg_info                ; buffer
  90.         move.l  #start-cfg_info,-(a7)   ; count
  91.         move.w  f_handle,-(a7)  ; handle
  92.         move.w  #$40,-(a7)
  93.         trap    #1              ; Fwrite
  94.         lea     12(a7),a7
  95.  
  96. .file_err       move.w  f_handle,-(a7)
  97.         move.w  #$3e,-(a7)
  98.         trap    #1              ; Fclose
  99.         addq.l  #4,a7
  100. .out    rts
  101.  
  102. .chk_sqsh       move.b  chk_sqsh,d0     ; checked Squished?
  103.         bne.s   .file_err               ; yep
  104.         cmp.l   #'DCSq',(a1)    ; Squished?
  105.         bne.s   .file_err               ; nope
  106.         clr.w   -(a7)           ; from beginning
  107.         move.w  f_handle,-(a7)  ; handle
  108.         move.l  d7,-(a7)                ; offset
  109.         move.w  #$42,-(a7)
  110.         trap    #1              ; Fseek (Squished file start)
  111.         lea     10(a7),a7
  112.         cmp.l   d7,d0           ; seek error?
  113.         bne.s   .file_err               ; yep
  114.         st      chk_sqsh
  115.         bra.s   .back
  116.  
  117.         DATA
  118. my_name:        dc.b    'TEST1234.PRG',0
  119.  
  120.         BSS
  121. chk_sqsh:       ds.b    1
  122. f_handle:       ds.w    1
  123.  
  124. scratch:        ds.b    cfg_info-BEGIN
  125.  
  126. ******************************
  127. * Second sample save routine *
  128. ******************************
  129.  
  130.         TEXT
  131.  
  132. my_fseek:
  133.         Fseek   #$26,d0,#0      ; fseek to 'DCSq' text
  134.         Fread   temp_fh,#4,#temp_buffer ; read it
  135.         cmp.l   #'DCSq',temp_buffer     ; is it squished?
  136.         bne.s   .0              ; nope
  137.         Fseek   #2,temp_fh,#0   ; fseek to 2 from beginning
  138.         Fread   temp_fh,#4,#temp_buffer ; read text size
  139.         add.l   #$3c,temp_buffer        ; add prog header size
  140.         Fseek   temp_buffer,temp_fh,#0  ; seek to my data area
  141.         rts
  142. .0:                             ; just seek to prog start
  143.         Fseek   #$20,temp_fh,#0
  144.         rts
  145.  
  146. *******************************
  147. * save the configuration info *
  148. *******************************
  149. save_info:
  150.         bsr     my_fseek
  151.         Fread   temp_fh,#8,#temp_buffer
  152.         cmp.l   #'TEST',temp_buffer
  153.         bne.s   .not_my_program
  154.         cmp.l   #'1234',temp_buffer+4
  155.         bne.s   .not_my_program
  156.         Fwrite  temp_fh,#config_size,#config_buffer
  157.         moveq   #0,d0
  158.         rts
  159. .not_my_program:
  160.         moveq   #-1,d0
  161.         rts
  162.  
  163.         BSS
  164.  
  165. temp_fh:
  166.         ds.w    1
  167. temp_buffer:
  168.         ds.l    2
  169.  
  170.  
  171.